package com.coreJava.test02;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 作者: LCG
 * 日期: 2019/9/3 11:03
 * 描述:
 */
public class Test8 {

    public static String test00(String name,int time){
        FutureTask<String> futureTask=new FutureTask<String>(new Callable<String>() {
            @Override
            public String call() throws Exception {

                Thread.sleep(time*1000);

                if(time==4){
                   throw new RuntimeException("线程"+Thread.currentThread().getName()+"出错了");
                }

                return "--当前线程-"+Thread.currentThread().getName();
            }
        });

        Thread thread=new Thread(futureTask,name);
        thread.start();

        try {

            return futureTask.get();
        } catch (Exception e) {
            e.printStackTrace();
            return "--当前线程-"+Thread.currentThread().getName()+"--出错了";
        }
    }

}
